﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleDatabaseAdapter
{
    public class AllDataItemsCollection<T> : IEnumerable, IEnumerator
    {
        private Type _ItemType;

        internal AllDataItemsCollection(SqlDataReader reader, List<ListColumnBase> columns)
        {
            _ItemType = typeof(T);
            Items = AllDataParser.ReadData<T>(reader, columns);
        }

        public List<T> Items { get; set; }
        public int Count
        {
            get
            {
                return Items.Count;
            }
        }
        public T this[int index]
        {
            get
            {
                return Items[index];
            }
        }

        // Реализуем интерейс IEnumerable
        public IEnumerator GetEnumerator()
        {
            return this;
        }

        // Реализуем интерфейс IEnumerator
        private int index = -1;
        public bool MoveNext()
        {
            if (index == Count - 1)
            {
                Reset();
                return false;
            }

            index++;
            return true;
        }
        public void Reset()
        {
            index = -1;
        }
        public object Current
        {
            get
            {
                return this[index];
            }
        }
    }
}
